<template>
	<!-- :class="{'table--border':border}"  -->
	<view @click="isClick()" class="uni-table-td" :class="{'table--border':border,'backColor':onClick}" 
	:style="{width:width + 'px','text-align':align,'background-color':onClick==true?'#00ff51':'',}">
		<slot></slot>
	</view>
</template>

<script>
	/**
	 * Td 单元格
	 * @description 表格中的标准单元格组件
	 * @tutorial https://ext.dcloud.net.cn/plugin?id=
	 * @property {Number} 	align = [left|center|right]	单元格对齐方式
	 */
	export default {
		name: 'uniTd',
		options: {
			virtualHost: true
		},
		props: {
			width: {
				type: [String, Number],
				default: ''
			},
			align: {
				type: String,
				default: 'left'
			},
		},
		data() {
			return {
				border: false,
				onClick:false,
			};
		},
		created() {
			this.root = this.getTable()
			this.border = this.root.border
		},
		methods: {
			/**
			 * 获取父元素实例
			 */
			getTable() {
				let parent = this.$parent;
				let parentName = parent.$options.name;
				while (parentName !== 'uniTable') {
					parent = parent.$parent;
					if (!parent) return false;
					parentName = parent.$options.name;
				}
				return parent;
			},
			isClick(){
				//debugger
				// if(this.onClick){
				// 	this.onClick=false;
				// }else{
				// 	this.onClick=true;
				// }
				this.$emit('isClick',this);
			},
		}
	}
</script>

<style scoped>
	.uni-table-td {
		display: table-cell;
		padding: 12px 10px;
		vertical-align: middle;
		border-bottom: 1px #ddd solid;
		color: #666;
		font-size: 14px;
		box-sizing: border-box;
	}
	/* .uni-table-td2 {
		display: table-cell;
		padding: 12px 10px;
		vertical-align: middle;
		border-bottom: 1px #ddd solid;
		color: #ff0000;
		font-size: 14px;
		box-sizing: border-box;
	} */
	.table--border {
		border-right: 1px #ddd solid;
	}
	.backColor {
		background-color: #00ff51;
	}
</style>